<?php

function smarty_function_load_view($params, &$smarty) {    
    $view_file_name = "";
    if (empty($params['name'])) 
        $smarty->trigger_error("missing 'name' attribute in <strong>load_view</strong> tag", E_USER_ERROR, __FILE__, __LINE__);
    else  $view_file_name = $params['name'].".tpl";

    $module = $smarty->get_current_mmodule();
    $theme  = $smarty->get_theme();
    
    if($smarty->is_admin_theme()){
         $view_file_location = "../../$module/admin_views/$view_file_name";
    }else{
        if(!$smarty->is_default_theme()){           
            if(file_exists(APPPATH . "views/$theme/$module/$view_file_name")){           
                $view_file_location = "../../views/$theme/$module/$view_file_name";
            }else{
                $view_file_location = "../../modules/$module/views/$view_file_name";
            }
        }else{
            $view_file_location = "../../$module/views/$view_file_name";
        }
    }

    $_params = array('smarty_include_tpl_file' =>  $view_file_location, 'smarty_include_vars' => (array)$params);
    $smarty->_smarty_include($_params);

}
?>